# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=java-libsignal-client
pkgver=0.58.2
pkgrel=0
pkgdesc="libsignal-client contains platform-agnostic APIs useful for Signal client apps"
url="https://github.com/signalapp/libsignal"
# java >= 11 not available on 32 bit archs
# s390x: build error in boringssl ("Unknown target CPU")
# ppc64le: build error in boringssl ("Unknown target CPU")
# riscv64: build error in boringssl ("Unknown target CPU")
# loongarch64: build error in boringssl ("Unknown target CPU")
arch="all !armhf !armv7 !x86 !ppc64le !s390x !riscv64 !loongarch64"
license="AGPL-3.0-or-later"
depends="java-jre-headless"
makedepends="bash cargo clang-dev cmake openjdk17-jdk protoc rust zip"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/signalapp/libsignal/archive/v$pkgver.tar.gz
	upgrade-gradle-fix-sigsegv-aarch64.patch
	java-libsignal-client-backport-boringssl-build-fix.patch
	"
install="$pkgname.post-install $pkgname.post-upgrade"
builddir="$srcdir/libsignal-$pkgver"
# tests succeed, but gradle aborts with exit value 134. have to further investigate later
options="!check"

build() {
	cd "$builddir"/java
	./gradlew --no-daemon -PskipAndroid :client:jar
}

check() {
	cd "$builddir"/java
	./gradlew --no-daemon -PskipAndroid :client:test
}

package() {
	install -D -m644 "$builddir"/java/client/build/libs/libsignal-client-$pkgver.jar \
		-t "$pkgdir"/usr/share/java/libsignal-client
	install -D -m755 "$builddir"/target/*-alpine-linux-musl/release/libsignal_jni.so \
		-t "$pkgdir"/usr/lib
	zip -d "$pkgdir"/usr/share/java/libsignal-client/libsignal-client-$pkgver.jar \
		libsignal_jni*.so
}

sha512sums="
96c0a003e8bef4e54b479e0b928fe7f4ec5c99bd798d3798e665c220adf552aa2222b6797fef6337bd285d6e1a059f75d284f92ef12e934b20d0efa70de2da02  java-libsignal-client-0.58.2.tar.gz
3a6f71075a01216fd02150f11bbc19a6ba26beb44b6b615e9cedbb2a0f9ead6a5e850e238db7d35a205830ee2fbb64f6228fd0e092af361658c5d7601ac835a6  upgrade-gradle-fix-sigsegv-aarch64.patch
65bbca1afda2750ef0be92238da69449dbc78eb78158fca004fae7f1be982b698ddb1fe7cd1db0d2f68d499e20e93d1767d74d66cdd1a914583c39eca7312774  java-libsignal-client-backport-boringssl-build-fix.patch
"
